var app = new Vue({
	el: '#app',
	extends:isLogin,
	mixins: [page, isLogin],
	components: {
		headers: header,
		navs:nav,
		footers:footer,
	},
	data: {
		bgImg:'img/PCindex/top5.jpg',
		navState:'求职招聘',
		searchData: '', //搜索数据
		searchContent: '', //搜索内容
		newJobData: '', //最新工作数据
		//		PageIndex: 1, //当前页数
		//		PageSize: 10, //获取数量
		JobClassData: '', //职业分类数据
		selected: '请选择', //职业分类选中
		salaryArr: ['面议', '2000以上', '4000以上', '6000以上', '8000以上', '10000以上', '15000以上', '20000以上', '30000以上', '50000以上'], //薪酬数据
		salary: '请选择', //薪酬
		workplace: '', //工作地点
	},
	watch: {
		searchContent: function(news, old) {
			this.totalPage = '';
		},
		selected: function(news, old) {
			this.totalPage = '';
		},
		salary: function(news, old) {
			this.totalPage = '';
		},
		workplace: function(news, old) {
			this.totalPage = '';
		},
	},
	methods: {
		//header组件的搜索方法
		searchHeader: function(searchCtx) {

		},
		//从求职页面点搜索进来的数据
		getNewsList: function() {
			console.log(this.totalPage)
			var _this = this;
			this.onePageCount = 10;
			var JobCategory = '';
			var Salary = '';
			var method = 'HR/SearchPosi';
			var searchContent = localStorage.getItem('searchContent');
			if(searchContent !== null) {
				this.searchContent = searchContent;
				var param = {
					Keyword: this.searchContent, //”职位名称或公司名称”,
					JobCategory: '', //” 职务分类”,
					Workplace: '', //“工资地点”
					Salary: '', //“ 薪酬”
					PageSize: _this.onePageCount, //” 获取数量”,
					PageIndex: _this.currentPage, //“ 当前页数”,
				};
				xq.getUrl(method, param, function(res) {
					if(res.data) {
						var data = res.data;
						localStorage.removeItem('searchContent');
						for(var i = 0; i < data.ListEntity.length; i++) {
							data.ListEntity[i].CreateDate = xq.getYMDHM(data.ListEntity[i].CreateDate, 'yy/mm/dd');
							if(data.ListEntity[i].OtherWelfare) {
								data.ListEntity[i].OtherWelfare = data.ListEntity[i].OtherWelfare.split(',')
							} else {
								data.ListEntity[i].OtherWelfare = [];
							}
						}
						if(!_this.totalPage) {
							_this.totalPage = Math.ceil(res.data.TotalCount / _this.onePageCount);
							_this.initPage();
						}
						_this.searchData = data;
					}
				});
			} else {
				var jsonData = JSON.parse(localStorage.getItem('jsonData'));
				var param = {};
				console.log(jsonData)
				this.searchContent = this.searchContent;
				if(this.selected == '请选择') {
					JobCategory = '';
				} else {
					JobCategory = this.selected;
				}
				if(this.salary == '请选择') {
					Salary = '';
				} else {
					Salary = this.salary;
				}
				this.workplace ? this.workplace : '';
				if(jsonData) {
					_this.searchContent =  jsonData.searchContent;
					_this.currentPage = jsonData.currentPage;
					_this.selected = jsonData.JobCategory;
					_this.salary = jsonData.Salary;
					_this.workplace = jsonData.workplace;
					param = {
						Keyword: jsonData.searchContent, //”职位名称或公司名称”,
						JobCategory: jsonData.JobCategory, //” 职务分类”,
						Workplace: jsonData.workplace, //“工资地点”
						Salary: jsonData.Salary, //“ 薪酬”
						PageSize: _this.onePageCount, //” 获取数量”,
						PageIndex: jsonData.currentPage, //“ 当前页数”,
					};
				} else {
					param = {
						Keyword: this.searchContent, //”职位名称或公司名称”,
						JobCategory: JobCategory, //” 职务分类”,
						Workplace: this.workplace, //“工资地点”
						Salary: Salary, //“ 薪酬”
						PageSize: _this.onePageCount, //” 获取数量”,
						PageIndex: _this.currentPage, //“ 当前页数”,
					};
				}
				xq.getUrl(method, param, function(res) {
					if(res.data) {
						var data = res.data;
						localStorage.removeItem('jsonData');
						for(var i = 0; i < data.ListEntity.length; i++) {
							data.ListEntity[i].CreateDate = xq.getYMDHM(data.ListEntity[i].CreateDate, 'yy/mm/dd');
							if(data.ListEntity[i].OtherWelfare) {
								data.ListEntity[i].OtherWelfare = data.ListEntity[i].OtherWelfare.split(',')
							} else {
								data.ListEntity[i].OtherWelfare = [];
							}
						}
						if(!_this.totalPage) {
							_this.pageArr = [];
							_this.totalPage = Math.ceil(res.data.TotalCount / _this.onePageCount);
							_this.initPage();
						}
						_this.searchData = data;
					}
				});
			}

		},
		//		//获取本职位推荐数据
		newJob: function(JobCategory) {
			var _this = this;
			var method = 'HR/SearchPosi';
			var param = {
				Keyword: '', //”职位名称或公司名称”,
				JobCategory: '', //” 职务分类”,
				Workplace: '', //“工资地点”
				Salary: '', //“ 薪酬”
				PageSize: _this.onePageCount, //” 获取数量”,
				PageIndex: _this.currentPage, //“ 当前页数”,
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					_this.newJobData = res.data.ListEntity;
				}
			});
		},
		//获取职位的分类
		getJobClass: function() {
			var _this = this;
			var method = 'HR/SearchJobCategory';
			var param = {
				JobCategory: '',
				PageSize: 0,
				PageIndex: 0,
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					_this.JobClassData = res.data;
				}
			});
		},
		//点击搜索按钮
		clickSearch: function() {
			this.getNewsList(this.currentPage);
		},
		//点击职位推荐职位
		clickCompanyJob: function(JobID) {
			localStorage.setItem('JobID', JobID);
			var jsonData = {
				currentPage: this.currentPage,
				JobCategory: this.selected,
				Salary: this.salary,
				Workplace: this.workplace,
				searchContent:this.searchContent,
			}
			localStorage.setItem('jsonData', JSON.stringify(jsonData));
			location.href = 'recruitDetail.html';
		}

	},
	mounted: function() {
		this.getNewsList();
		this.newJob();
		this.getJobClass();
	},
	updated: function() {

	}
})